 WaterHistoryRecordForm = Ext.extend(Ext.Window, {
	// 头部工具栏
		topbar : null,
		// 条件搜索Panel
		searchPanel : null,
		// 数据展示Panel
		gridPanel : null,
		// GridPanel的数据Store
		store : null,		
		width : 700,
		height : 490,
		// 构造函数
		constructor : function(_cfg) {
			Ext.applyIf(this, _cfg);
			// 初始化组件
			this.initUIComponents();
			// 调用父类构造
			WaterHistoryRecordView.superclass.constructor.call(this, {
						id : 'WaterDetailHistoryRecordForm',
						title : '水表明细查询',
						region : 'center',
						layout : 'border',
						modal : true,
						plain : true,
						buttonAlign : 'center',
						items : [this.searchPanel, this.gridPanel]
					});

		},// end of constructor

		// 初始化组件
		initUIComponents : function() {
			// 初始化搜索条件Panel
			var buttonName = "";
			var statusValue = "";
			var ynUse=true;
			if(this.type=="2"){
				buttonName = "停用";
				statusValue = "使用中";
				ynUse=false;
			}else if(this.type=="3"){
				buttonName="启用";	
				statusValue = "已报废";
				ynUse=true;
			}else if(this.type=="1"){
				buttonName="停用";	
				statusValue = "申请中";
				ynUse=true;
			}else if(this.type=="4"){
				buttonName="启用";	
				statusValue = "停用中";
				ynUse=false;
			}
			
			
			
			this.searchPanel = new Ext.FormPanel({
						id : 'WaterDetailHistoryRecordSearchForm',
						height : 130,
						region : 'north',
						frame : false,
						border : false,
						padding : '10',
						layout : 'column',
						title : '',
						labelWidth : 60,
//						enctype : 'multipart/form-data',
//						fileUpload : true,
//						url : __ctxPath + '/pdaweb/searchListPdaWaterList.do',
						layoutConfig : {
							padding : '5',
							align : 'middle'
						},
						defaults : {
							columnWidth : 0.33,
							layout : 'form',
							border : false,
							style : 'padding-left:10px;',
							defaults : {
								xtype : 'textfield',
								width : 130
							}
						},
						items : [{
									items : [{  
												id : 'amID_S',
												fieldLabel : '水表编号',
												name : 'Q_amId_S_EQ',
												value : this.recId,
												readOnly: true,
												style:'color:#666666'
											},{
												fieldLabel : '房号',
												name : 'Q_pdaWaterMeter.aparmentId_S_EQ',
												value : this.fangId,
												disabled : true
											},{
												fieldLabel : '抄表人',
												name :'Q_recorderId_S_LK',
												dataIndex : 'recorderId'
											},{
												fieldLabel : '当前状态',
												id : 'type_status',
												readOnly : true,
												style : 'color:#666666',
												width : 80,
												value : statusValue
											
											}]
								}, {
									items : [{
												fieldLabel : '区号',
												name : 'Q_pdaWaterMeter.districtId_S_EQ',
												value : this.quId,
												readOnly: true,
												style:'color:#666666'
											},{
												fieldLabel : '开始年月',
												xtype : 'monthfield',
												value : new Date().add(Date.YEAR,-1),
												editable : false,
												allowblank : false,
												name : 'Q_month_S_GE'
											},{
												xtype : 'button',
												text : '查询',
												region : 'center',
												width : 60,
												iconCls : 'search',
												style : 'margin-center:10px',
												scope : this,
												handler : function(){
													var searchPanel = Ext.getCmp('WaterDetailHistoryRecordSearchForm');
													var gridPanel = Ext.getCmp('WaterDetailHistoryRecordGrid');
													if (searchPanel.getForm().isValid()) {
														$search({
															searchPanel : searchPanel,
															gridPanel : gridPanel
														});
													}
												}

											},{
												xtype : '',
												width :1,
												height:2,
												border :false
											},{														 
												style : 'padding-left:0px;margin-top:3px',
                                                xtype : isGranted('_WT_PAUSE')?'button':'hidden',
												iconCls : 'btn-reset',
												text : buttonName,
												width : 60,
												id : 'pauseButton',
												disabled : ynUse,
												handler : function() {
													WaterHistoryRecordForm.updateMeter();
												}
											
											}]
								}, {
									items : [{
												fieldLabel : '栋号',
												name : 'Q_pdaWaterMeter.buildingId_S_EQ',
												value : this.dongId,
												readOnly: true,
												style:'color:#666666'
											},{
												fieldLabel : '结束年月',
												xtype : 'monthfield',
												value : new Date(),
												editable : false,
												allowblank : false,
												name : 'Q_month_S_LE'
											} ]
								},{
										items : [{
											xtype:'hidden',
											name : 'Q_status_S_SIN',
											value: '0,1,2,3'
										},{
											xtype : 'hidden',
											id : 'am_type',
											value : this.type
										}]
				              }]
					});// end of the searchPanel

			this.store = new Ext.data.Store({
						proxy : new Ext.data.HttpProxy({
									url : __ctxPath + '/pdaweb/searchListPdaWaterList.do',
									params : {
										Q_status_S_SIN : '0,1,2,3,4',
										start : 0,
										limit : 12
									}
								}),
						reader : new Ext.data.JsonReader({
									root : 'result',
									totalProperty : 'totalCounts',
									fields : [{
												name : 'id',
												type : 'int'
											}, 'status', 'amId', 
											'degree', 
											'pdaWaterMeter.districtId','usage',
											'pdaWaterMeter.buildingId',
											'pdaWaterMeter.aparmentId',
											'recorderId', 'month']
								}),
						remoteSort : true
					});// end of the store
			
			this.store.baseParams = {
					Q_amId_S_EQ : this.recId,
					Q_month_S_GE : new Date().add(Date.YEAR,-1).format('Y-m'),
					Q_month_S_LE : new Date().format('Y-m'),
					Q_status_S_SIN : '0,1,2,3,4'
			}
			this.store.load({
				params : {
					start : 0,
					limit : 12				
				}
			});

			var cm = new Ext.grid.ColumnModel({
						columns : [ new Ext.grid.RowNumberer(),{
									header : '抄表年月',
									width : 100,
									dataIndex : 'month'
								},{
									header : '读数',
									width : 100,
									dataIndex : 'degree'
								}, {
									header : '当月用量',
									width : 100,
									dataIndex : 'usage'
								}, {
									header : '抄表人',
									width : 100,
									dataIndex : 'recorderId'
								}],
						defaults : {
							sortable : true,
							menuDisabled : false
							//width : 100
						}
					});// end of the cm


			this.topbar = new Ext.Toolbar(
					{
						id : 'WaterHistorRecordFootBar',
						height : 20,
						bodyStyle : 'text-align:left;',
						items : []
					});
			
			this.gridPanel = new Ext.grid.GridPanel({
						id : 'WaterDetailHistoryRecordGrid',
						tbar : this.topbar,
						region : 'center',
						store : this.store,
						trackMouseOver : true,
						disableSelection : false,
						loadMask : true,
						autoHeight : true,
						cm : cm,
						bbar : new Ext.PagingToolbar({
									pageSize : 12,
									store : this.store,
									displayInfo : true,
									displayMsg : '当前显示从{0}至{1}， 共{2}条记录',
									emptyMsg : "当前没有记录"
								})
					});

			var gridPanel = this.gridPanel;
		}
});
 
 WaterHistoryRecordForm.updateMeter = function() {
		var vType = Ext.getCmp('am_type').getValue();
		var recId = Ext.getCmp('amID_S').getValue();
		Ext.getCmp('pauseButton').setDisabled(true);
		var alertS="";
		if(vType=="2"){
			alertS="停用成功";
		}else{
			alertS="启用成功";	
		}
			Ext.Ajax.request({
			url : __ctxPath + '/pdaweb/pausePdaWaterMeter.do?recId=' + recId+'&vType='+vType,
			waitMsg : '正在提交数据...',
			timeout : 30000,
			method : 'post',
			success : function(response) {
				
				Ext.ux.Toast.msg("操作信息",alertS);
				if(vType=="2"){
				Ext.getCmp('am_type').setValue("4");
				Ext.getCmp('type_status').setValue("停用中");
				Ext.getCmp('pauseButton').setText("启用");				
				}else{
				Ext.getCmp('am_type').setValue("2");
				Ext.getCmp('type_status').setValue("使用中");
				Ext.getCmp('pauseButton').setText("停用");
				}
				Ext.getCmp('WaterHistoryRecordGrid').getStore().reload();
				Ext.getCmp('pauseButton').setDisabled(false);
			},
			failure : function() {
				//			Ext.Msg.alert("操作信息", "审核失败");
				Ext.getCmp('pauseButton').setDisabled(false);
				Ext.MessageBox.show({
					title : '操作信息',
					msg : '操作失败',
					buttons : Ext.MessageBox.OK,
					icon : 'ext-mb-error'
				});
			}
		});
	}
